
//格式定义
let userG = (/^[A-z]\w{3,15}$/);
let pwG = (/^[A-z0-9]{4,16}$/);
let emailG = (/^[1-9a-zA-Z_]\w*@[a-zA-Z0-9]+(\.[a-zA-Z]{2,})+$/);
var city002=[
    ["东城","西城","朝阳","丰台","石景山","海淀","门头沟","房山","通州","顺义","昌平","大兴","平谷","怀柔","密云","延庆"],
    ["和平","河东","河西","南开","河北","红桥","东丽","西青","津南","北辰","宁河","武清","静海","宝坻","蓟县","滨海新区"]
];


//用户名验证
function checkusername(){
    let username=document.getElementById("userName");
    if(username.value==""){
        document.getElementById("userNameMessage").className="errorMessage";
        document.getElementById("userNameMessage").innerHTML="不能为空";
        document.getElementById("userNameImage").className="errorImage";
    }else if(userG.test(username.value)==false){
        document.getElementById("userNameMessage").className="errorMessage";
        document.getElementById("userNameMessage").innerHTML="输入格式不正确";
        document.getElementById("userNameImage").className="errorImage";
    }else{
        document.getElementById("userNameMessage").className="successMessage";
        document.getElementById("userNameMessage").innerHTML="输入格式正确";
        document.getElementById("userNameImage").className="successImage";
    }
}

//昵称验证
function checknickname(){
    let nickname=document.getElementById("nickName");
    if(nickname.value==""){
        document.getElementById("nickNameMessage").className="errorMessage";
        document.getElementById("nickNameMessage").innerHTML="不能为空";
        document.getElementById("nickNameImage").className="errorImage";
    }else{
        document.getElementById("nickNameMessage").className="successMessage";
        document.getElementById("nickNameMessage").innerHTML="输入正确";
        document.getElementById("nickNameImage").className="successImage";
    }
}

//密码验证
function checkpassword(){
    let password=document.getElementById("password");
    if(password.value==""){
        document.getElementById("passwordMessage").className="errorMessage";
        document.getElementById("passwordMessage").innerHTML="不能为空";
        document.getElementById("passwordImage").className="errorImage";
    }else if(pwG.test(password.value)==false){
        document.getElementById("passwordMessage").className="errorMessage";
        document.getElementById("passwordMessage").innerHTML="输入格式不正确";
        document.getElementById("passwordImage").className="errorImage";
    }else{
        document.getElementById("passwordMessage").className="successMessage";
        document.getElementById("passwordMessage").innerHTML="输入格式正确";
        document.getElementById("passwordImage").className="successImage";
    }
}

//重复密码验证
function checkrepassword(){
    let password=document.getElementById("password");
    let repassword=document.getElementById("rePassword");
    if(repassword.value==""){
        document.getElementById("rePasswordMessage").className="errorMessage";
        document.getElementById("rePasswordMessage").innerHTML="不能为空";
        document.getElementById("rePasswordImage").className="errorImage";
    }else if(repassword.value!=password.value){
        document.getElementById("rePasswordMessage").className="errorMessage";
        document.getElementById("rePasswordMessage").innerHTML="输入密码不一致";
        document.getElementById("rePasswordImage").className="errorImage";
    }else{
        document.getElementById("rePasswordMessage").className="successMessage";
        document.getElementById("rePasswordMessage").innerHTML="输入正确";
        document.getElementById("rePasswordImage").className="successImage";
    }
}


//城市选择
// function checkcity(){
//     var sltCity01=document.form_reg.city01;   //获得一级城市下拉框的对象
//     var sltCity02=document.form_reg.city02;     //获得二级城市下拉框的对象
//     var city001=city002[sltCountry.selectedIndex-1];    //得到对应城市数组
//     sltCity01.length=1;    //清空城市下拉框，仅留提示选项。
//     //通过for循环，将城市中的值填充到城市下拉框中
//     for(var i=0;i<city001.length;i++){
//         sltCity001[i+1]=new Option(city001[i],city001[i]);
//     }   
// }


//邮箱验证
function checkemail(){
    let email=document.getElementById("email");
    if(email.value==""){
        document.getElementById("emailMessage").className="errorMessage";
        document.getElementById("emailMessage").innerHTML="不能为空";
        document.getElementById("emailImage").className="errorImage";
    }else if(emailG.test(email.value)==false){
        document.getElementById("emailMessage").className="errorMessage";
        document.getElementById("emailMessage").innerHTML="输入格式不正确";
        document.getElementById("emailImage").className="errorImage";
    }else{
        document.getElementById("emailMessage").className="successMessage";
        document.getElementById("emailMessage").innerHTML="输入格式正确";
        document.getElementById("emailImage").className="successImage";
    }
}